package com.hs.jhzd.controller;

import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hs.jhzd.entity.SystemNotice;
import com.hs.jhzd.service.message.NoticeProducer;
import com.hs.jhzd.service.message.RoutingkeyEnums;

@Controller
@RequestMapping("/r")
public class RollcallController {

  @Lazy
  @Autowired
  private NoticeProducer noticeProducer;

  @RequestMapping("/start")
  @ResponseBody
  public boolean start(String jsh, @RequestParam(defaultValue = "10") Integer limitedTime) {
    SystemNotice systemNotice = new SystemNotice();
    Map<String, Object> param = new HashMap<>();
    param.put("limitedTime", limitedTime);
    systemNotice.setOrder(SystemNotice.ORDER_ROLLCALL);
    systemNotice.setParam(param);
    String routingKey = StringUtils.isBlank(jsh) ? RoutingkeyEnums.TERMINAL_ALL.getName()
        : RoutingkeyEnums.TERMINAL.getName() + jsh;
    noticeProducer.sendMessage(routingKey, systemNotice);
    noticeProducer.sendMessage(RoutingkeyEnums.CLIENT.getName(), systemNotice);
    return true;
  }
}
